<?php
namespace Home\Controller;
use Think\Controller;
use Org\Type\CatTree;
use Think\Page;
class SearchController extends Controller{
	public function index(){

            //实例化商品分类
            $cats=M('Cats');
            //查询所有类别
            $allcats=$cats->field('catsid,catsname,pid,path')->select();
            //调用分类函数
            $type = CatTree::getlist($allcats);
            //为模板变量赋值
            $this->assign('type',$type);


        // --------------------搜索处理-----------------------------

            $res=M('Goods');
            $keyword=$_GET['keyword'];

            $sear['goodsname'] = array('like','%'.$keyword.'%');
            // 导入分页类
            import('Think.Page');
            //查询数据条数
            $count=$res->where($sear)->count();
            //实例化分页函数
            $Page=new Page($count,8);
            //设置页码显示
            $Page->setConfig('header', '共 %TOTAL_ROW% 条记录');
            $Page->setConfig('first', '首页');
            $Page->setConfig('last', '末页');
            $Page->setConfig('prev','<<');
            $Page->setConfig('next','>>');
            $Page->setConfig('theme',"共 %TOTAL_ROW% 条记录 %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%");
            //分页跳转的时候维持查询条件
            foreach($sear as $key=>$val) {
                    $Page->parameter[]   =   "$key=".urlencode($val[1]).'&';
            }
            //分页按钮显示输出
            $show=$Page->show();
            // 进行分页数据查询
            $val=$res->where($sear)->limit($Page->firstRow.','.$Page->listRows)->select();
            $this->assign('ugoods',$val);
            $this->assign('page',$show);
            $this->display();

	}

        public function search() {

        }
	
}